
import 'dart:ui';

import 'package:flutter/material.dart';

import '../../../components/animate_meau_list.dart';
import '../../../components/dialog/msg_dialog.dart';
import '../../../components/infor_card.dart';
import '../../../components/semicircle_card.dart';
import '../../../constant/constant.dart';
import '../../../internal/http/dao/get_self_dao.dart';
import '../../../models/response.dart';

class ProfileScreen extends StatefulWidget {
  const ProfileScreen({super.key});

  @override
  State<ProfileScreen> createState() => _ProfileSreenState();
}

class _ProfileSreenState extends State<ProfileScreen> {
  int userId = 0;
  String account = "";
  String username = "";
  String email = "cilanguser@gmail.com";

  @override
  void initState() {
    super.initState();

    _loadUserData();
  }

  @override
  Widget build(BuildContext context) {
    // final textTheme = Theme.of(context).textTheme;
    final size = MediaQuery.sizeOf(context);
    return Container(
        decoration:
            BoxDecoration(gradient: LinearGradient(colors: bgGradientColor)),
        height: size.height,
        child: Stack(
          children: [
            SemiCircle(
              height: size.width * 0.5,
            ),
            Positioned(
              top: size.width * 0.10,
              width: size.width,
              height: size.width,
              child: Container(
                margin: const EdgeInsets.all(50),
                child: ClipRect(
                  child: BackdropFilter(
                    filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
                    child: Container(
                      alignment: Alignment.center,
                      width: 10,
                      height: 10,
                    ),
                  ),
                ),
              ),
            ),
            Positioned(
              top: size.width * 0.10,
              width: size.width,
              height: size.width,
              child: InforCard(
                height: size.width,
                color: Colors.white.withOpacity(0.8),
                userId: userId,
                username: username,
                account: account,
                email: email,
              ),
            ),
            Positioned(
                top: size.width * 0.9,
                width: size.width,
                height: size.height,
                child: Container(
                  padding: const EdgeInsets.all(14),
                  child: const AnimateMeauList(),
                ))
          ],
        ));
  }

  // 加载用户数据
  Future<void> _loadUserData() async {
    // 获取自身信息
    TiebaResponse response = await GetSelfInfoDao.get();
    if (response.code == 200) {
      if (mounted) {
        setState(() {
          userId = response.result["id"];
          account = response.result["account"];
          username = response.result["username"];
          email = response.result["email"];
        });
      }
    } else {
      // ignore: use_build_context_synchronously
      MsgDialog.msgDialog(context, response.msg);
    }
  }
}
